import { GetServerSideProps, NextPage, PageConfig } from 'next';
import Head from 'next/head';
import anylogger from 'anylogger';
import Content from './content';
import queryallcurriculums from '../../api/teachgl/queryallcurriculums';
import { tbcurriculums } from '../../../atoms/db';


const logger = anylogger('pages/teachgl/pk/index.page');

export interface IName {
	class_id: string;
	name: string;
}

interface IProps {
	data: IName[];
}

/**
 * 排课
 */
const Page: NextPage<IProps> = ({ data }) => {
	return (
		<>
			<Head>
				<title>排课</title>
			</Head>
			<Content initialdata={data} />
		</>
	);
};

export const config: PageConfig = {
	amp: false
};

export default Page;

// pre-render this page on each request
export const getServerSideProps: GetServerSideProps<IProps> = async (context) => {
	const data = await tbcurriculums()
		.distinct('grade', 'trem_name', 'class', 'class_id');
	return {
		props: {
			data: data.map((it) => {
				return {
					name: `${it.grade}—${it.trem_name}—${it.class}`,
					class_id: it.class_id
				};
			})
		}
	};
};
